const { URL } = require('url')

// const parse = new URL('https://www.baidu.com:9000/detail?id=1&page=1#name')

// console.log( parse )

// const myURL = new URL('/foo', 'https://example.org/')
// console.log( myURL )

const url = require('url')
const href = 'https://www.baidu.com:9000/detail?id=1&page=1#name'
console.log( url.parse(href) )
/* Url {
  protocol: 'https:',
  slashes: true,
  auth: null,
  host: 'www.baidu.com:9000',
  port: '9000',
  hostname: 'www.baidu.com',
  hash: '#name',
  search: '?id=1&page=1',
  query: 'id=1&page=1',
  pathname: '/detail',
  path: '/detail?id=1&page=1',
  href: 'https://www.baidu.com:9000/detail?id=1&page=1#name'
} */

/* URL {
  href: 'https://www.baidu.com/detail?id=1&page=1#name',
  origin: 'https://www.baidu.com',
  protocol: 'https:',
  username: '',
  password: '',
  host: 'www.baidu.com',
  hostname: 'www.baidu.com',
  port: '',
  pathname: '/detail',
  search: '?id=1&page=1',
  searchParams: URLSearchParams { 'id' => '1', 'page' => '1' },
  hash: '#name'
} */